<div class="form-container">
	<form id="form">
		<table class="tableform">
			<tr>
				<th style="width:70px;">所属公司：</th>
				<td>
					<input id="company" name="company_id" class="easyui-validatebox" type="text" style="width: 188px; height:25px;" />
				</td>
				<th style="width:70px;">所属部门：</th>
				<td>
					<input id="dept" name="dept_id" class="easyui-validatebox" type="text" style="width: 188px; height:25px;" />
				</td>
			</tr>
			<tr>
				<th style="width:70px;">用户账号：</th>
				<td>
					<input name="account" class="easyui-validatebox" type="text" data-options="required: true" style="width:180px;"/>
				</td>
				<th style="width:70px;">用户密码：</th>
				<td>
					<input name="password" class="easyui-validatebox" type="password" style="width:180px;"/>
				</td>
			</tr>
			<tr>
				<th>姓名：</th>
				<td>
					<input name="truename" class="easyui-validatebox" type="text" data-options="required: true" style="width:180px;"/>
				</td>
				<th>电子邮件：</th>
				<td>
					<input name="email" class="easyui-validatebox" type="text" data-options="required: true" style="width:180px;"/>
				</td>
			</tr>
			<tr>
				<th>性别：</th>
				<td>
					<input id="gender" name="gender" style="width:188px;height:25px;">
				</td>
				<th>出生日期：</th>
				<td>
					<input name="birthday" class="Wdate" style="width:185px;" type="text" onFocus="WdatePicker({isShowClear:true,readOnly:true})"/>
				</td>
			</tr>
			<tr>
				<th>手机：</th>
				<td>
					<input name="mobile" class="easyui-validatebox" type="text" style="width:180px;"/>
				</td>
				<th>电话：</th>
				<td>
					<input name="telephone" class="easyui-validatebox" type="text" style="width:180px;"/>
				</td>
			</tr>
			<tr>
				<th>锁定：</th>
				<td colspan="3">
					<div id="icheck">
						<input id="i1" type="radio" name="locked" value="1" checked="checked">
						<label class="irl" for="i1">正常</label>　
						<input id="i2" type="radio" name="locked" value="-1">
						<label class="irl" for="i2">锁定</label>　
					</div>
				</td>
			</tr>
			<tr style="display:none">
				<td>
					<input type="hidden" name="id" value="${id!}">
				</td>
			</tr>
		</table>
	</form>
</div>

<script>
	var form_url = "${ctx}/manager/base/user/add", id = "${id!}" ;
	var $company, $dept;
	$(function(){
		$('#icheck input').iCheck({
			checkboxClass: 'icheckbox_minimal-blue',
			radioClass: 'iradio_square-blue'
	   	});
	   	
	   	$company = $("#company").combotree({
			url: "${ctx}/manager/base/company/treegrid",  method: "GET",
			idFiled:'companyId', editable: false, required: true, lines:true, autoShowPanel: false,
			url : "${ctx}/manager/base/company/treegrid",
			editable: false, lines:true, method: "GET",
			onChange: function(newValue, oldValue) {
				if(undefined != oldValue && null != oldValue) {
					$dept.combotree({
						url: "${ctx}/manager/base/dept/treegrid/"+newValue
					});
				}
            },
            onLoadSuccess: function(node,data) {
				$company.combotree("setValue", data[0].id);
			}
		});
		$dept = $("#dept").combotree({
			method: "GET", idFiled:'pid', editable: false, required:false, lines:true, autoShowPanel: false
		});
	   	
   		$("#gender").combobox({
			textField: 'label', valueField: 'label', value: '男',
			data: [{ label: '男', value: '男' },{ label: '女', value: '女' }],
			panelHeight:'auto', editable:false, autoShowPanel: true
		}) ;
		
		if(undefined != id && "" != id) {
			form_url = "${ctx}/manager/base/user/update" ;
			$.ajax({
				type: "GET", dataType: "JSON",
				url: "${ctx}/manager/base/user/get/"+id,
				success: function(result) {
					$("input[name=locked][value="+result.locked+"]").iCheck('check') ;
					
					if(undefined != result.company_id) {
						$company.combotree("setValue", result.company_id);
						$dept.combotree("setValue", result.dept_id);
					}
					
					$("#form").form("load", result); 
					
					$("input[name=password]").attr("type", "text").val("密码不可编辑").prop("disabled", "true") ;
				},
				complete: function(XMLHttpRequest, textStatus){},
				error: function(XMLHttpRequest, textStatus, errorThrown){
					$.easyui.loaded();
					if(XMLHttpRequest.status == 403) {
						$.messager.alert(XMLHttpRequest.statusText, XMLHttpRequest.responseText, "warning");
					} else {
						$.messager.alert("错误", "发生未知错误", "error");
					}
				}
			});
		}
		
	});
	
	//提交表单数据
	var submitNow = function($d, $dg, flag) {
		$.post(form_url, $("#form").form("getData"), function(result) {
			if (result.status) {
				$dg.datagrid('reload');alertify.success(result.message);$.easyui.loaded();
				if(flag==undefined||flag==false){$d.dialog("close") ;}
			} else {
				$.easyui.loaded();$.messager.alert("错误", result.message, "error");
			}
		}, 'json').error(function() { $.easyui.loaded(); });
	};
	
	//验证表单
	var submitForm = function($d, $dg, flag) { 
		if($('#form').form('validate')) {
			$.easyui.loading({ msg: "数据提交中，请稍等..." });
			submitNow($d, $dg, flag) ;
		}
	};
</script>

